//using System;
//using System.IO;
//using System.Data;
//using System.Data.SqlClient;
//using System.Collections;
//using System.Configuration;
//
//namespace ProcessesSMS
//{
//	/// <summary>
//	/// Summary description for.
//	/// Project name: SMS_xoso
//	/// channel: n/a
//	/// command code: HN X Y
//	/// created: 01/09/09 .
//	/// Writer : Nampt + Tuanbc
//	/// Company: VIT TELECOM
//	/// </summary>
//
//	public class XONGDATXONGNHA
//	{
//		#region Declare
//		private SMS_MO WMO;
//		private SMS_MT WMT;
//		ArrayList arr = new ArrayList();
//		public XONGDATXONGNHA(SMS_MO MO)
//		{
//			WMO = MO;
//		}
//
//		public XONGDATXONGNHA()
//		{
//		}
//		#endregion
//		public void run()
//		{
//			WMT = new SMS_MT(WMO);
//			string tmpMsg = WMO.Message.Substring(WMO.CommandCode.Length).Trim().Replace("  ", " ").Replace("  ", " ");
//			tmpMsg = tmpMsg.Replace("  ", " ").Trim();
//			//string[] msg = tmpMsg.Split(new char[] { ' ' });
//			string strReturnMsg = "";            
//			strReturnMsg = GetReturnMsg(tmpMsg);
//			string[] tmpRtMessage = strReturnMsg.Split('.');
//			string rtMessage="";
//			if(tmpRtMessage.Length==5)
//			{
//				rtMessage= tmpRtMessage[0] +"\n"+ tmpRtMessage[1];
//				WMT.AddMessage(WMO.UserID, rtMessage, SMS_ContentType.SMS_TEXT);
//				WMT.MsgType = SMS_MsgType.SMS_TINHTIEN;
//				
//				rtMessage= tmpRtMessage[2] +"\n"+ tmpRtMessage[3];
//				WMT.AddMessage(WMO.UserID, rtMessage, SMS_ContentType.SMS_TEXT);
//				WMT.MsgType = SMS_MsgType.SMS_TINHTIEN;
//
//				rtMessage= tmpRtMessage[4] + "\n";
//				WMT.AddMessage(WMO.UserID, rtMessage, SMS_ContentType.SMS_TEXT);
//				WMT.MsgType = SMS_MsgType.SMS_TINHTIEN;
//
//				WMT.Insert(); 
//			}
//			else if (rtMessage.Length==6)
//			{
//				rtMessage= tmpRtMessage[0] +"\n"+ tmpRtMessage[1];
//				WMT.AddMessage(WMO.UserID, rtMessage, SMS_ContentType.SMS_TEXT);
//				WMT.MsgType = SMS_MsgType.SMS_TINHTIEN;
//				
//				rtMessage= tmpRtMessage[2] +"\n"+ tmpRtMessage[3];
//				WMT.AddMessage(WMO.UserID, rtMessage, SMS_ContentType.SMS_TEXT);
//				WMT.MsgType = SMS_MsgType.SMS_TINHTIEN;
//
//				rtMessage= tmpRtMessage[4] +"\n"+ tmpRtMessage[5];
//				WMT.AddMessage(WMO.UserID, rtMessage, SMS_ContentType.SMS_TEXT);
//				WMT.MsgType = SMS_MsgType.SMS_TINHTIEN;
//
//				WMT.Insert(); 
//			}
//			else
//			{
//				WMT.AddMessage(WMO.UserID, strReturnMsg, SMS_ContentType.SMS_TEXT);
//				WMT.MsgType = SMS_MsgType.SMS_TINHTIEN;
//
//				WMT.Insert(); 
//			}
//			return;   
//		}
//		public string GetReturnMsg(string arr)
//		{
//			string Help_XongDatXongNha = "";
//			Help_XongDatXongNha = "Ban da nhan sai cu phap tin nhan!\n";
//			Help_XongDatXongNha += "De xem thong tin Xong dat - Xong nha,\n";
//			Help_XongDatXongNha += "Soan tin:\n";
//			Help_XongDatXongNha += "XD <tuoi cua ban> gui 6772\n";
//			Help_XongDatXongNha += "Vi du: Ban tuoi Dan, soan tin:\n";
//			Help_XongDatXongNha += "XD DAN 6772";
//			string msgBody="";
//			string[] array = WMO.Message.Split(' ');
//			if (WMO.ServiceID.Replace("04","")=="6072")
//			{
//				string strSQL="";
//				strSQL ="SELECT Description FROM XONGDAT_XONGNHA\n";
//				strSQL += "WHERE Age='" + array[1] + "'";
//				SqlConnection sqlconn = new SqlConnection(ConfigSettings.ReadSetting("STOCK_CONNECTION_STRING"));
//				sqlconn.Open();
//				SqlDataAdapter da = new SqlDataAdapter(strSQL, sqlconn);
//				DataSet ds = new DataSet();
//				da.Fill(ds);
//				if (ds.Tables[0].Rows.Count==0)
//				{
//					msgBody = Help_XongDatXongNha;
//				}
//				else
//				{
//					msgBody = ds.Tables[0].Rows[0]["Description"].ToString();
//				}
//				sqlconn.Close();
//			}
//			else
//			{
//				msgBody = Help_XongDatXongNha;
//			}
//			return msgBody;
//		}
//	}		
//}
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized;

namespace ProcessesSMS
{
	/// <summary>
	/// Summary description for.
	/// game name: THI TIM HIEU HA NOI VA THI TRUONG CHUNG KHOAN 
	/// channel: n/a
	/// command code: HN X Y
	/// created: 20/03/07 .
	/// Writer : Hungncv .
	/// </summary>
	/// 
	//--Tren bao ANTD-->///
	///AN_X_Y : 8359 (X: A,B,C,D : Chuong trinh HN ngan nam van hien)
	public class XONGDATXONGNHA
	{
		#region Declare
		private SMS_MO WMO;
		private SMS_MT WMT;
		ArrayList arr = new ArrayList();

		public XONGDATXONGNHA(SMS_MO MO)
		{
			WMO = MO;
		}

		public XONGDATXONGNHA()
		{
		}
		#endregion
		#region Method
		public void run()
		{
			WMT = new SMS_MT(WMO);

			string tmpMsg = WMO.Message.Substring(WMO.CommandCode.Length).Trim().Replace("  ", " ").Replace("  ", " ");
			tmpMsg = tmpMsg.Replace("  ", " ").Trim().ToUpper();           
			string[] msg = tmpMsg.Split(new char[] { ' ' });

			string strReturnMsg = "";            
			strReturnMsg = GetReturnMsg(msg);
			if (strReturnMsg.Length>160 && strReturnMsg.Length<=320)
			{
				string temp;
				temp = strReturnMsg;
				strReturnMsg = temp.Substring(0,160);
				WMT.AddMessage(WMO.UserID, strReturnMsg, SMS_ContentType.SMS_TEXT);
				WMT.MsgType = SMS_MsgType.SMS_TINHTIEN;

				strReturnMsg = temp.Substring(160);
				WMT.AddMessage(WMO.UserID, strReturnMsg, SMS_ContentType.SMS_TEXT);
				WMT.MsgType = SMS_MsgType.SMS_TINHTIEN;
				WMT.Insert(); 
			}
			else
			{
				WMT.AddMessage(WMO.UserID, strReturnMsg, SMS_ContentType.SMS_TEXT);
				WMT.MsgType = SMS_MsgType.SMS_TINHTIEN;
				WMT.Insert(); 
			}
			return;  
		}

		private string GetReturnMsg(string[] arr)
		{
			string connString = ConfigurationSettings.AppSettings["STOCK_CONNECTION_STRING"].ToString();
			string msgBody = "";
			string Help_XongDatXongNha = "";
			Help_XongDatXongNha = "Ban da nhan sai cu phap tin nhan!\n";
			Help_XongDatXongNha += "De xem thong tin Xong dat - Xong nha,\n";
			Help_XongDatXongNha += "Soan tin:\n";
			Help_XongDatXongNha += "XD <tuoi cua ban> gui 6772\n";
			Help_XongDatXongNha += "Vi du: Ban tuoi Dan, soan tin:\n";
			Help_XongDatXongNha += "XD DAN 6772";
			if ((WMO.ServiceID.Replace("04","") == "6772") || (WMO.UserID=="841278882664"))
			{
				string strSQL="";
				strSQL ="SELECT Description FROM XONGDAT_XONGNHA\n";
				strSQL += "WHERE Age='" + arr[0] + "'";
				SqlConnection sqlconn = new SqlConnection(ConfigSettings.ReadSetting("STOCK_CONNECTION_STRING"));
				sqlconn.Open();
				SqlDataAdapter da = new SqlDataAdapter(strSQL, sqlconn);
				DataSet ds = new DataSet();
				da.Fill(ds);
				if (ds.Tables[0].Rows.Count==0)
				{
					msgBody = Help_XongDatXongNha;
				}
				else
				{
					msgBody = ds.Tables[0].Rows[0]["Description"].ToString();
				}
			}
			else
			{
				msgBody = Help_XongDatXongNha;
			}
			return msgBody;
		}
			#endregion Method
	}
}
